package com.obelisco.vista.controles;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Locale;

import nextapp.echo2.app.ApplicationInstance;

import com.jgoodies.binding.adapter.echo.TextComponentConnector;
import com.jgoodies.binding.beans.PropertyAdapter;
import com.jgoodies.binding.value.ConverterFactory;
import com.jgoodies.binding.value.ValueModel;

public class BindingDateField extends DateField {

	//ValueModel model = null;
	PropertyAdapter model = null;

	ValueModel model2 = null;
	//PropertyAdapter model2 = null;

	TextComponentConnector connector = null;

	public BindingDateField(int ancho) {
		super(ancho);
		// TODO Auto-generated constructor stub
	}

	public BindingDateField(int ancho, Object object, String property) {
		this(ancho);
		if (connector != null) {
			connector.release();
		}
		if (model == null) {
			model = new PropertyAdapter(object, property, true);
		} else {
			model.setBean(object);
		}
		DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM,
				ApplicationInstance.getActive().getLocale());
		model2 = ConverterFactory.createStringConverter(model, df);
		connector = new TextComponentConnector(model2, this.txtFecha);
		connector.updateTextComponent();
	}

	public void setBinding(Object object, String property) {
		if (connector != null) {
			connector.release();
		}
		if (model == null) {
			model = new PropertyAdapter(object, property, true);
		} else {
			model.setBean(object);
		}
		DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM,
				ApplicationInstance.getActive().getLocale());
		model2 = ConverterFactory.createStringConverter(model, df);
		connector = new TextComponentConnector(model2, this.txtFecha);
		connector.updateTextComponent();
	}

}
